//
//  AssetDetailVC.m
//  ZZLC
//
//  Created by 杨春至 on 2017/12/16.
//  Copyright © 2017年 ZhongZeng. All rights reserved.
//

#import "AssetDetailVC.h"
#import "AssetDetailTableViewCell.h"
#import "Me_Model.h"
#import "AssetDetailView.h"
#import "AssetRingView.h"


@interface AssetDetailVC ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic)NSArray *contentDataSouece;
@property(nonatomic)NSArray *contentMoneyDataSouece;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (copy, nonatomic)  NSString *totolMoneyLabelStr;//总额
@property (copy, nonatomic)  NSString *availableMoneyLabelStr;//账户余额
@property (copy, nonatomic)  NSString *freezeMoney;//投资中金额
@property (copy, nonatomic)  NSString *wfsy;//待结算收益
@property (copy, nonatomic)  NSString *totalProfit;//已结算

@property (nonatomic,strong) AssetRingView *ringView;

@property(nonatomic)AssetDetailView *headerView ;
@end

@implementation AssetDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"资产明细";
    [self loadData];
    self.contentDataSouece = @[@"账户余额(元)",@"投资中金额(元)",@"待结算收益(元)",@"已结算收益(元)"];
    AssetDetailView *headerView = [[NSBundle mainBundle]loadNibNamed:@"AssetDetailView" owner:self options:nil][0];
    self.headerView = headerView;
//    [self.tableView setTableHeaderView:headerView];
    [self.view addSubview:self.ringView];
    // Do any additional setup after loading the view from its nib.
}
- (void)loadData
{
 
    [NetWorkingManager postWithRequestUrl:@"User/showMyAccount" AndParameters:@{@"parameters":[@{@"authorization":[UserModel authorization]?[UserModel authorization]:@""} DataTOjsonStringAndAddVersion]} AndRequestBlock:^(NSDictionary *responseObject) {
        [self configUIByData:responseObject];
    } FailBlock:^(NSDictionary *errDic) {
        NSLog(@"%@",errDic);
    }];
}
- (void)configUIByData:(NSDictionary*)dic
{
    NSDictionary *userDic = dic[@"obj"];
    
    Me_Model *meModel = [Me_Model objectWithKeyValues:userDic];

    self.totolMoneyLabelStr = [NSString stringWithFormat:@"%0.2f",[meModel.totalMoney doubleValue]/100];//资产总额
    self.headerView.totoLLabelMoney.text = self.totolMoneyLabelStr;
      self.availableMoneyLabelStr = [NSString stringWithFormat:@"%0.2f",[meModel.leftMoney doubleValue]/100];//账户余额
    self.freezeMoney = [NSString stringWithFormat:@"%0.2f",[meModel.freezeMoney doubleValue]/100];//投资中金额
    self.wfsy = [NSString stringWithFormat:@"%0.2f",[meModel.wfsy doubleValue]/100];//待结算收益
      self.totalProfit = [NSString stringWithFormat:@"%0.2f",[meModel.totalProfit doubleValue]/100];//已经结算收益
     self.contentMoneyDataSouece = @[self.availableMoneyLabelStr,self.freezeMoney, self.wfsy, self.totalProfit ];
    [self.tableView reloadData];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"AssetDetailTableViewCell" owner:self options:nil];
    AssetDetailTableViewCell *cell = [nibs firstObject];
    cell.contentLabel.text = self.contentDataSouece[indexPath.row];
    cell.moneyLabel.text = self.contentMoneyDataSouece[indexPath.row];
    return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return self.headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (KWidth>320) {
        return 200;
    }else return 140;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.5;
}

- (AssetRingView *)ringView{
    if (!_ringView) {
        _ringView = [[AssetRingView alloc]initWithFrame:CGRectMake(0, (KWidth>320?220:160)+64, KWidth, KHeight - (KWidth>320?220:160))];
    }
    return _ringView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
